/**
 * @Title: CaptchaService
 * @Package cn.com.artemis.framework.service.captcha.service
 * @Description: TODO
 * Copyright: Copyright (c) 2016
 * Company: 成都壹柒互动科技有限公司
 * @author 会员系统组-胥钰淋
 * @date 2016/11/7 16:06
 * @version V1.0
 */
package cn.com.yiqi.wsc.service.captcha;


import cn.com.yiqi.wsc.common.CaptchaType;
import cn.com.yiqi.wsc.service.captcha.utils.GoogleKaptcha;
import cn.com.yiqi.wsc.service.captcha.utils.PmCaptcha;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 会员系统组-胥钰淋
 * @ClassName: CaptchaService
 * @Description: TODO
 * @date 2016/11/7 16:06
 */
@Service
public class CaptchaService {

    @Autowired
    private GoogleKaptcha googleKaptcha;

    @Autowired
    private PmCaptcha pmCaptcha;

    private CaptchaType type = CaptchaType.adminLogin;

    /**
     * 获取验证码图片
     *
     * @param request  请求
     * @param response 响应
     * @param type     验证码类型
     */
    public void getCaptcha(HttpServletRequest request, HttpServletResponse response, CaptchaType type) {
        if (null != type) {
            this.type = type;
        }
      /*  if (CaptchaEnum.KAPTCHA.equals(this.type)) {
            googleKaptcha.getCaptcha(request, response);
        } else if (CaptchaEnum.GENERAL.equals(this.type)) {*/
        pmCaptcha.getCaptcha(request, response);
//        }
    }

    /**
     * 验证用户输入的验证码
     *
     * @param request 请求
     * @param captcha 用户输入的验证码
     * @return 通过与否
     */
    public boolean validate(HttpServletRequest request, String captcha) {
        boolean result = true;
//        if (CaptchaEnum.KAPTCHA.equals(this.type)) {
//            result = googleKaptcha.validate(request, captcha);
//        } else if (CaptchaEnum.GENERAL.equals(this.type)) {
        result = pmCaptcha.validate(request, captcha);
//        }
        return result;
    }

}
